package com.songxh.facade.controller;

import com.songxh.application.api.BlogDetailsService;
import com.songxh.application.dto.details.*;
import com.songxh.core.base.CommonResult;
import com.songxh.infrastructure.db.pojo.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author songxh
 * @create 2022-12-20-15:23
 */
@RestController
@RequestMapping("/gra/songxh/details")
public class BlogDetailsController {

    @Autowired
    private BlogDetailsService blogDetailsService;

    /**
     * 展示博客内容详情
     * @param detailsParamsDTO
     * @return
     */
    @PostMapping("/show")
    public CommonResult<DetailsResultDTO> showDetails(@RequestBody DetailsParamsDTO detailsParamsDTO){
         return blogDetailsService.showDetails(detailsParamsDTO);
    }

    /**
     * 获取评论信息
     * @param articleId
     * @return
     */
    @GetMapping("/article/{id}")
    public CommonResult<List<CommentResultDTO>> getComments(@PathVariable("id") Long articleId){
        return CommonResult.success(blogDetailsService.getComments(articleId));
    }

    /**
     * 新增评论
     * @param commentParamsDTO
     * @return
     */
    @PostMapping("/comment")
    public CommonResult comment(@RequestBody CommentParamsDTO commentParamsDTO){
        blogDetailsService.comment(commentParamsDTO);
        return CommonResult.success();
    }

    /**
     * 创建文章时展示所有标签
     * @return
     */
    @PostMapping("/getTag")
    public CommonResult<List<TagResultDTO>> getTags(){
        List<TagResultDTO> tags = blogDetailsService.getTags();
        return CommonResult.success(tags);
    }

    /**
     * 创建文章时展示所有标签
     * @return
     */
    @PostMapping("/getCategory")
    public CommonResult<List<CategoryResultDTO>> getCategory(){
        List<CategoryResultDTO> category = blogDetailsService.getCategory();
        return CommonResult.success(category);
    }

    /**
     * 保存文章
     * @param articleParamDTO
     * @return
     */
    @PostMapping("/save")
    public CommonResult save(@RequestBody InsertArticleParamDTO articleParamDTO){
        blogDetailsService.save(articleParamDTO);
        return CommonResult.success();
    }

}
